<template>
  <view>
    <u-navbar
      v-if="!$isWeixin()"
      :custom-back="backToList"
      :title-width="450"
      :title="title"
      :titleBold="true"
      :is-fixed="true"
      :background="{ backgroundColor: '#FFFFFF' }"
    ></u-navbar>

    <u-tabs active-color="#FF7A23" :list="tabList" :current="tabIndex" @change="index => (tabIndex = index)"></u-tabs>

    <view class="" v-if="tabIndex == 0 && SelectType != 4">
      <relations :list="detail.This_Dealer_RelationList"></relations>
    </view>

    <view class="" v-if="tabIndex == 1 && SelectType != 4">
      <u-cell-item
        v-if="detail.ShowLevel != 1"
        title="一级经销商名称"
        :arrow="false"
        :border-bottom="detail.ShowLevel == 3"
        :value="detail.First_Dealer_BaseInfo.Name"
      ></u-cell-item>

      <view class="" v-if="detail.ShowLevel != 3">
        <basic-information
          :data="DealerInfo"
          :showOtherInfo="false"
          :level="detail.ShowLevel"
          :showReview="false"
          :showParent="false"
          :showDeliveryAddress="false"
        ></basic-information>
      </view>

      <view class="" v-show="detail.ShowLevel == 3">
        <u-cell-item
          title="二级经销商名称"
          :arrow="false"
          :border-bottom="false"
          :value="detail.Double_Dealer_BaseInfo.Name"
        ></u-cell-item>
        <store-information :loadCity="false" :data="detail.Door_Dealer_BaseInfo"></store-information>
      </view>
    </view>

    <view v-if="(tabIndex == 2 && SelectType != 4) || (tabIndex == 0 && SelectType == 4)">
      <design-information
        v-if="loadData"
        :data="DesignInfo"
        :showReview="true"
        :selectType="SelectType"
      ></design-information>
    </view>

    <view class="btn-group-fixed"><u-button @tap="backToList">返回列表</u-button></view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      title: '设计详情',

      SelectType: 1,

      tabList: [{ name: '销售业务关系' }, { name: '基本信息' }, { name: '设计信息' }],
      tabIndex: 0,
      ApplyId: null,

      detail: {
        ShowLevel: null,
        First_Dealer_BaseInfo: {},
        Double_Dealer_BaseInfo: {},
        Door_Dealer_BaseInfo: {},
        This_Dealer_OtherInfo: {},
        DealerAuditInfo: {},
        This_Dealer_RelationList: [],
        InitialPhotoList: [],
        DesignPhotoList: [],
        FileList: []
      },

      DealerInfo: {
        Dealer_BaseInfo: {},
        Dealer_OtherInfo: {}
      },

      loadData: false,

      DesignInfo: {
        InitialPhotoList: [],
        DesignPhotoList: [],
        FileList: [],
        DealerAuditInfo: {},
        AuditForList: [],
        ObjectType: '',
        DoorPlane: '',
        OutDoorAdvertising: '',
        Media: ''
      }
    };
  },

  onLoad(options) {
    if (options.ApplyId) {
      this.ApplyId = options.ApplyId;
    }

    if (options.SelectType) {
      this.SelectType = options.SelectType;

      if (options.SelectType == 2) {
        this.title = '专卖店设计申请';
      }
      if (options.SelectType == 3) {
        this.title = '其他设计申请';
      }
      if (options.SelectType == 4) {
        this.title = '其他设计申请';
        this.tabList = [{ name: '设计信息' }];
      }
    }

    this.getData();

    if (this.$isWeixin()) {
      this.$setTitle(this.title);
    }
  },
  methods: {
    backToList() {
      uni.navigateBack();
    },

    getData() {
      this.$u.api
        .getDesignReviewDetail({
          ApplyId: this.ApplyId
        })
        .then(res => {
          const { ResultCode, ResultMessage, ResultData } = res;

          if (ResultCode === 1) {
            this.detail = ResultData;

            if (this.detail.DealerAuditInfo.ObjectType == 4) {
              this.SelectType = 4;
              this.title = '其他设计审核详情';
              this.tabList = [{ name: '设计信息' }];
            }

            if (this.detail.ShowLevel == 1) {
              this.DealerInfo.Dealer_BaseInfo = this.detail.First_Dealer_BaseInfo;
            }
            if (this.detail.ShowLevel == 2) {
              this.DealerInfo.Dealer_BaseInfo = this.detail.Double_Dealer_BaseInfo;
            }

            this.DesignInfo.DesignPhotoList = this.detail.DesignPhotoList;
            this.DesignInfo.DealerAuditInfo = this.detail.DealerAuditInfo;
            this.DesignInfo.FileList = this.detail.FileList;
            this.DesignInfo.InitialPhotoList = this.detail.InitialPhotoList;
            this.DesignInfo.AuditForList = this.detail.AuditForList;

            this.DesignInfo.ObjectType = this.detail.DealerAuditInfo.ObjectType;
            this.DesignInfo.DoorPlane = this.detail.DealerAuditInfo.DoorPlane;
            this.DesignInfo.OutDoorAdvertising = this.detail.DealerAuditInfo.OutDoorAdvertising;
            this.DesignInfo.Media = this.detail.DealerAuditInfo.Media;

            this.DesignInfo.DesignType = this.detail.DealerAuditInfo.DesignType;
            this.DesignInfo.objectType = this.detail.DealerAuditInfo.ObjectType;

            let DesignTypeList = [];
            if (this.detail.DealerAuditInfo.ObjectType == 5) {
              DesignTypeList = this.detail.GraphicDesigns;
            }
            if (this.detail.DealerAuditInfo.ObjectType == 4) {
              DesignTypeList = this.detail.HeadquartersDesigns;
            }
            if (this.detail.DealerAuditInfo.ObjectType == 3) {
              DesignTypeList = this.detail.OtherDesigns;
            }
            this.DesignInfo.DesignTypeList = DesignTypeList;

            this.loadData = true;
          }
        });
    }
  }
};
</script>

<style lang="scss"></style>
